var id=$('#providerId').val();

$(function(){
	$('#name').focus();
	setMyActive(6,1); //设置激活页
	$.fn.zTree.init($("#treeDemo"), setting, zNodes);
	checkProvince();
});

var setting = {
		check : {
			enable : true,
			chkStyle : "checkbox",
			chkboxType : {
				"Y" : "p",
				"N" : "s"
			}
		},
		data : {
			simpleData : {
				enable : true
			}
		},
		view: {
			showIcon: false
		}
	};

var zNodes = $.parseJSON(initZTreeNodes());

function checkProvince(){
	var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
	treeObj.checkAllNodes(false);
	$.ajax({
		type:'GET',
		url :basePath +'providerBillPkgDetail/'+id,
		success:function (data){
			$.each(data, function(index,val) {
				var initProvince = treeObj.getNodeByParam("id", val.province_code, null);
				var initCity = treeObj.getNodeByParam("id", val.province_code+'-'+val.city_code, null);
				initProvince.checked = true; 
				treeObj.updateNode(initProvince); 
				if(initCity!=null){
					initCity.checked = true; 
					treeObj.updateNode(initCity); 
				}
			});
	    },
	    dataType: 'json'
	});
}

function saveProvince(){
	var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
	var nodes = treeObj.getCheckedNodes(true);
	var meg='';
	if(nodes.length>0){
		for(var i=0;i<nodes.length;i++){
			var m =nodes[i].id;
			meg+=m+',';
		}
	}
	$('#provinceMeg').val(meg);
}

//加载单选按钮providerId的样式
function initCheckBoxStyle(){  
	$('input[type=checkbox]').iCheck({
		checkboxClass: 'icheckbox_square-green',
		radioClass: 'iradio_square-green',
	});
}